#include "assign_group_dialog.h"
#include <QFile>
#include <QTextStream>
#include <QTableWidgetItem>
#include <QMessageBox>

AssignGroupDialog::AssignGroupDialog(QWidget *parent) : QDialog(parent)
{
    ui.setupUi(this);
    loadStudents();
}

void AssignGroupDialog::loadStudents()
{
    QFile file("students.txt");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QMessageBox::warning(this, "错误", "无法打开students.txt文件！");
        return;
    }
    QTextStream in(&file);
    int row = 0;
    while (!in.atEnd()) {
        QString line = in.readLine().trimmed();
        if (line.isEmpty()) continue;
        QStringList parts = line.split(",");
        if (parts.size() == 2) {
            ui.tableWidget->insertRow(row);
            ui.tableWidget->setItem(row, 0, new QTableWidgetItem(parts[0].trimmed()));
            ui.tableWidget->setItem(row, 1, new QTableWidgetItem(parts[1].trimmed()));
            row++;
        }
    }
} 